﻿using FourGroups.Project;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using WMS.Seven.Models;

namespace WMSProject.SuJiaHao
{
    [ApiExplorerSettings(GroupName = "苏佳豪")]
    public class ProductsService : ApplicationService, IProductsService
    {
        /// <summary>
        /// 可出库存管理仓储
        /// </summary>
        private readonly IRepository<Products, int> _productsRepository;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="productsRepository">可出库存管理仓储</param>
        public ProductsService(IRepository<Products, int> productsRepository)
        {
            _productsRepository = productsRepository;
        }

        /// <summary>
        /// 获取可出库存管理列表
        /// </summary>
        /// <param name="pageSize">页容量</param>
        /// <param name="pageIndex">当前页</param>
        /// <returns>返回可出库存管理列表</returns>
        public async Task<ReturnSelect<object>> GetProductsList(int pageIndex, int pageSize)
        {
            // 获取生产领料列表
            var productsList = await _productsRepository.GetListAsync();

            //// 使用 WhereIf 进行条件筛选
            //var lossReportingLists = lossReportingList
            //    .WhereIf(!string.IsNullOrEmpty(reportNumber), x => x.ReportNumber == reportNumber)
            //    .ToList();

            // 计算总记录数和当前页记录
            var totalCount = productsList.Count;
            var pageList = productsList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            var result = AutoMapperExt.MapToList<Products>(pageList);

            //返回结果
            var data = new { TotalCount = totalCount, PageList = result };
            return new ReturnSelect<object>(true, "0", result != null && result.Count > 0 ? data : null);
        }
    }
}
